Fix handling of UpdateBehavior.WRITE_IF_NOT_EXISTS on @DynamoDbAutoGeneratedUuid #6391
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
Fixed the behavior of the
@DynamoDbAutoGeneratedUuidannotation in combination with@DynamoDbUpdateBehavior(UpdateBehavior.WRITE_IF_NOT_EXISTS).Previously, a new UUID was generated even when the attribute already had a value. With this change:
UUID.randomUUID()).WRITE_IF_NOT_EXISTS, existing values in DynamoDB are preserved using theif_not_exists(...)expression.This ensures that UUIDs are only generated once for attributes tagged with
WRITE_IF_NOT_EXISTSand remain stable across subsequent updates.Important Note
Stringattribute.@DynamoDbAutoGeneratedKey(implementation added with this PR) , this extension does not enforce PK/SK or index-only usage — it supports non-key attributes.putItem, the entire item is always replaced, so if the field is absent, a new UUID will still be generated, even withWRITE_IF_NOT_EXISTS.Motivation and Context
#5703
This bug fix improves consistency with the documented semantics of
WRITE_IF_NOT_EXISTSand matches user expectations.Modifications
AutoGeneratedUuidExtensionto only generate UUIDs if the attribute is missing or empty.WRITE_IF_NOT_EXISTS.AutoGeneratedUuidExtensionTestand functional tests inAutoGeneratedUuidRecordTestto verify:WRITE_ALWAYSvs.WRITE_IF_NOT_EXISTS.Testing
putItemandupdateItem.Test Coverage Checklist
Types of changes
Checklist
mvn installsucceedsscripts/new-changescript and following the instructions. Commit the new file created by the script in.changes/next-releasewith your changes.License